package com.xiaoma.verbal.webservice;

import java.io.BufferedReader;
import java.io.PrintWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xiaoma.verbal.domain.PrctScoreRecord;
import com.xiaoma.verbal.dto.CorrectedAudioDto;
import com.xiaoma.verbal.service.PrctAssistantService;
import com.xiaoma.verbal.service.PrctPracticeAudioService;
import com.xiaoma.verbal.service.PrctScoreRecordService;

@Controller
@RequestMapping("/service/practice/assistant")
public class PrctAssistantWS {
	@Autowired
	private PrctAssistantService prctAssistantService;
	@Autowired
	private PrctPracticeAudioService prctPracticeAudioService;

	@Autowired
	private PrctScoreRecordService prctScoreRecordService;

	@RequestMapping(value = "/completeToeflPractice", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> completeToeflPractice(@RequestBody CorrectedAudioDto audio) {
		Map<String, Object> result = new HashMap<String, Object>();
		Integer status = 1;
		String msg = "success";
		try {
			if (audio != null) {
				PrctScoreRecord record = this.prctScoreRecordService.fillScore(audio);
				if(record!=null){
				this.prctScoreRecordService.pushMsgToBaidu(audio);
				}
			} else {
				status = 0;
				msg = "数据传输为空！";
			}
		} catch (Exception e) {
			status = 0;
			e.printStackTrace();
			msg = e.getMessage();
		}
		result.put("status", status);
		result.put("msg", msg);
		return result;
	}

	private void pushMessage(Integer id) {
		try {
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
